import axios from 'axios'

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  withCredentials: true,
  timeout: 10000
})

// axios请求拦截器
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// axios响应拦截器
service.interceptors.response.use(
  response => {
    const res = response.data
    if (res) {
      return Promise.resolve(res)
    } else {
      return Promise.reject('请求失败')
    }
  },
  error => {
    return Promise.reject(error)
  }
)

export default service

